package com.ssm.service.imp;

import com.github.pagehelper.PageHelper;
import com.ssm.mapper.UserMapper;
import com.ssm.pojo.User;
import com.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    public void insert(User user) {
        userMapper.insert(user);
    }

    public void update(User user) {
        userMapper.update(user);
    }

    public void delete(String userName) {
        userMapper.delete(userName);
    }

    public List<User> selectUserPage(Integer pageNum, Integer pageSize, String userName) {
        if(pageNum!=null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<User> users= userMapper.selectUsersPage(userName);
        return users;
    }

    public Integer countSize(String userName) {
        Integer size = userMapper.countSize(userName);
        return size;
    }

    public User selectUserByName(String userNae) {
        User user = userMapper.selectByUserName(userNae);
        return user;
    }

    public User selectByNameAndPassword(String userName,String password) {
        User user = userMapper.selectByUserNameAndPsssword(userName,password);
        return user;
    }
}
